package com.caiyi.financial.nirvana.sms.handler;

import com.caiyi.financial.nirvana.sms.jedis.JedisService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class ApplicationHandler implements ApplicationContextAware {

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        JedisService.init(host, port, maxTotal, maxIdle, maxWaitMillis, timeout);
        start(applicationContext);
    }

    public void start(ApplicationContext applicationContext) {
    }

    public String host;
    public int maxTotal;
    public int maxIdle;
    public long maxWaitMillis;
    public int timeout;
    public int port;

    @Value("${redis.host}")
    public void setHost(String host) {
        this.host = host;
    }

    @Value("${redis.maxTotal}")
    public void setMaxTotal(int maxTotal) {
        this.maxTotal = maxTotal;
    }

    @Value("${redis.maxIdle}")
    public void setMaxIdle(int maxIdle) {
        this.maxIdle = maxIdle;
    }

    @Value("${redis.maxWaitMillis}")
    public void setMaxWaitMillis(long maxWaitMillis) {
        this.maxWaitMillis = maxWaitMillis;
    }

    @Value("${redis.timeout}")
    public void setTimeout(int timeout) {
        this.timeout = timeout;
    }

    @Value("${redis.port}")
    public void setPort(int port) {
        this.port = port;
    }

}
